﻿@{
    ViewBag.Title = "MiniSetting";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="refresh" plain="true">刷新</a>
                     <span class="separator"></span>
                    <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>
                    <a class="mini-button" id="save" name="save" iconCls="icon-edit" onclick="modify" plain="true">修改</a>
                    <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeInfo" plain="true">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="uploadcode" name="uploadcode" iconCls="icon-expand" onclick="uploadcode" plain="true">上传代码</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>       
    </div>        

        @Html.Partial("~/Views/Modular/SearchInfo.cshtml")
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetMiniSetList"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FName" name="FName" width="100" headeralign="center" allowsort="true">应用名称</div>
                    <div field="FAppID" name="FAppID" width="200" headeralign="center" allowsort="true">小程序AppID</div>
                    <div field="FAppSecret" name="FAppSecret" width="270" headeralign="center" allowsort="true">小程序AppSecret</div>                 
                    <div field="FCreateTime" name="FCreateTime" width="100" headeralign="center" allowsort="true">创建时间</div>
                    <div field="FRemark" name="FRemark" width="150" headeralign="center" allowsort="true">备注</div>
                </div>
            </div>
        </div>

<script>
    function FormShown() {
        mini.parse();
        LoadListData();
    }

    function setkeyPress() {
        LoadListData();
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");//==
        grid.load({ mjson: json });
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    //刷新
    function refresh() {
        mini.getbyName("FSearchKey").setValue('');
        LoadListData();
    }

    //上传小程序代码
    function uploadcode() {
        parent.window.showTabById('UploadCode', '上传小程序代码', '../SmallProgramSetting/UploadCode');
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/System/MiniSetInfo",
            title: "小程序设置", width: 550, height: 350,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/System/MiniSetInfo",
                title: "小程序设置", width: 550, height: 350,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除资料
    function removeInfo() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定删除选中记录？", "提示",
            function (action) {
                if (action == "ok") {

                    var json = "{'FItemID':'" + row.FItemID + "'}";
                    $.post("RemoveMiniSetInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                        var ret = mini.decode(data);
                        if (ret.status == 1) {
                            grid.reload();
                        }
                        else {
                            mini.alert("异常:" + ret.error);
                        }
                    });
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }

</script>